import { get_patient_train_record } from '@/services/patient';
import time from '@/utils/time';
import { ProColumns, ProTable } from '@ant-design/pro-components';
import { useRef } from 'react';
type GithubIssueItem = {
  icon: string;
  id: string;
  name: string;
  training_date: string;
  video_time: string;
  number: string;
  status: number;
};
interface Iprops {
  patientId: number | undefined;
}
const TrainingRecord = (props: Iprops) => {
  const { patientId } = props;
  const actionRef = useRef();

  // 获取训练记录
  const get_recordlist = async (params: {
    pageSize?: number | undefined;
    current?: number | undefined;
    keyword?: string | undefined;
  }) => {
    //默认分页参数和后端接口字段不匹配
    let request_body = {
      ...params,
      current: params.current,
      pageSize: params.pageSize,
      old_id: patientId,
    };
    let res = await get_patient_train_record(request_body);
    console.log('训练记录列表', res);
    return {
      data: res.data.list,
      success: true,
      total: res.data.total_count,
    };
  };
  const columns: ProColumns<GithubIssueItem>[] = [
    {
      title: '视频',
      dataIndex: 'icon',
      align: 'center',
      key: 'icon',
      render: (_: any, record: { icon: string | undefined }) => {
        return (
          <img
            style={{
              height: '50px',
              width: '50px',
            }}
            src={record.icon}
          />
        );
      },
    },
    {
      title: '视频名称',
      align: 'center',
      dataIndex: 'name',
      key: 'name',
    },
    {
      title: '日期',
      dataIndex: 'training_date',
      align: 'center',
      key: 'training_date',
    },
    {
      title: '视频时长',
      dataIndex: 'video_time',
      align: 'center',
      key: 'video_time',
      render: (_: any, record: any) => {
        return time(record.video_time);
      },
    },
    {
      title: '训练次数',
      dataIndex: 'number',
      align: 'center',
      key: 'number',
    },
    {
      title: '训练状态',
      dataIndex: 'status',
      align: 'center',
      key: 'status',
      valueType: 'select',
      valueEnum: {
        0: {
          text: '未开始',
        },
        1: {
          text: '已训练',
        },
        2: {
          text: '已完成',
        },
        3: {
          text: '未完成',
        },
      },
    },
  ];
  return (
    <div>
      <ProTable
        columns={columns}
        actionRef={actionRef}
        request={async (params = {}) => get_recordlist(params)}
        rowKey={(record) => record.id}
        search={false}
        toolBarRender={false}
        size="middle"
        pagination={{
          pageSize: 10,
          showSizeChanger: false,
        }}
        dateFormatter="string"
      />
    </div>
  );
};

export default TrainingRecord;
